if (islogin()) {
    $('#op').click(function () {
        var button1=[
            {
                text:'添加',
                onClick:function () {
                    window.location.href='add_teacher.html';
                }
            }
        ];
        var button2=[{
            text:'取消',
        }];
        var groups=[button1,button2];
        $$.actions(groups);
    });

    $.post({
        url:'../requests/admin/select_teacher.php',
        success:function (data) {
            for (var i = 0; i < data.nums.length; i++) {
                var dom="<ul>" +
                            "<li class='item-content'>" +
                                "<div class='item-inner'>"+
                                    "<div class='item-title'>账号</div>"+
                                    "<div class='item-after t_num'>"+data.nums[i]+"</div>"+
                                "</div>"+
                            "</li>"+
                            "<li class='item-content'>" +
                                "<div class='item-inner'>"+
                                    "<div class='item-title'>姓名</div>"+
                                    "<div class='item-after'>"+data.names[i]+"</div>"+
                                "</div>"+
                            "</li>"+
                            "<li class='item-content'>" +
                                "<div class='item-inner'>"+
                                    "<div class='item-title'></div>"+
                                    "<div class='item-after'>" +
                                        "<button class='button button-dark btn_del' value='ddd'>删除</button>"+
                                        "<button class='button button-dark btn_edit'>编辑</button>"+
                                        "<button class='button button-dark btn_reset'>重置密码</button>"+
                                     "</div>"+
                                "</div>"+
                            "</li>"+
                        "</ul>"
                $('.list-block').append(dom);
            }
        }
    });

    //删除
    $('.list-block').on('click','.btn_del',function () {
        var that=$(this);
        $$.confirm('删除教师将删除该教师有关的所有数据','是否继续',function () {
            var num=that.parent().parent().parent().parent().find('.t_num').html();
            $.post({
                url:'../requests/admin/del_teacher.php',
                data:{'num':num},
                success:function (data) {
                    if (data == 'no_login') {
                        window.location.href='login.html';
                    }
                    else if (data == '1') {
                        $$.alert('删除成功',function () {
                            location.reload(true)
                        });
                    }
                    else{
                        $$.alert('删除失败',function () {
                            location.reload(true)
                        });
                    }
                }
            });
        });
    });
    //修改
    $('.list-block').on('click','.btn_edit',function () {
        var num=$(this).parent().parent().parent().parent().find('.t_num').html();
        window.location.href='edit_teacher.html?'+num;
    });
    // 重置密码
    $('.list-block').on('click','.btn_reset',function () {
        var that=this;
        $$.confirm('确认重置密码？',function () {
            var num=$(that).parent().parent().parent().parent().find('.t_num').html();
            $.post({
                url:'../requests/admin/reset_psw.php',
                data:{'num':num},
                success:function (data) {
                    if (data == '1') {
                        $$.alert('重置成功');
                    }
                    else if (data == 'no_exist') {
                        $$.alert('账号不存在!',function () {
                            location.reload(true);
                        });
                    }
                    else {
                        $$.alert('重置失败！',function () {
                            location.reload(true);
                        });
                    }
                }
            });
        });

    });
}